import OrderService from "@/api/order/OrderService.js";
export default {
  beforeCreate(){
    if(Object.prototype.toString.call(this.$options.propsData.CTOInfo) === "[object Object]"){
      let ppmCondition = {
        offerId: this.$options.propsData.CTOInfo.prodOfferId,
        productId: this.$options.propsData.CTOInfo.prodId,
        prodName: this.$options.propsData.CTOInfo.offerName,
        serviceOfferId: "-1", //新装所有产品固定值
        modType: "50200003", //新装所有产品固定值
        optionId: this.$options.propsData.ODKInfo.taskId, //新装所有产品固定值
      };
      
      
      
      sessionStorage.setItem("ppmCondition", JSON.stringify(ppmCondition));
    }
  },
  computed: {
    CTOInfos: {
      set: function (value) {
        return value;
      },
      get: function () {
        if (Object.prototype.toString.call(this.CTOInfo) === "[object Object]") {
          let t = JSON.parse(JSON.stringify(this.CTOInfo)),
              arr = [];
          arr.push(t);
          return arr;
        } else {
          return this.CTOInfo;
        }
      },
    }
  },
  beforeMount() {
    //设置属性
    
    
    this.productName(this.ppmParams);
    if(this.ODKInfo.tacheId=='TACHE0005'){
      // 资费核实
      sessionStorage.setItem("proName", "zfhs10450");
      var orderItemIds = "";
      for (var i = 0; i < this.CTOInfos.length; i++) {
        if (i == 0) {
          orderItemIds += this.CTOInfos[i].orderItemId;
        } else {
          orderItemIds += "," + this.CTOInfos[i].orderItemId;
        }
      }
      sessionStorage.setItem("cacheInfo", JSON.stringify({
        productId: this.CTOInfos[0].prodId,
        taskId:this.ODKInfo.taskId,
        OrgId:this.user.orgId,
        serviceOfferId:this.CTOInfos[0].offerId,
        orderItemIds:orderItemIds
      }));
    }
  },
  watch:{
    formData: {
      handler(newValue,oldValue) {
        if(JSON.stringify(newValue) != '{}'){
          let structIdObj = {};
          for(var key in this.formData){
            let keyArr = key.split('-');
            structIdObj[keyArr[0]]='';
          }
          for(var key in structIdObj){
            if(this.formData[key+"-100012377"]){
              this.formData[key+"-100012377"].value = this.user.staffName;
            }
            if(this.formData[key+"-141000048"]){
              this.formData[key+"-141000048"].value = this.user.staffId;
            }
            if(this.formData[key+"-100012440"]){
              this.formData[key+"-100012440"].value = this.$util.dateFormat(new Date(),"yyyy-MM-dd");
            }
            if(this.formData[key+"-100012611"]&&this.taskReqDate){
                this.formData[key+"-100012611"].value = this.$util.dateFormat(this.taskReqDate,"yyyy-MM-dd");
            }
          }
        }
      },
    }
  },
  mounted() {
  },
  methods:{
    /**
     * 获取js
     */
    async productName(params) {
      let result = await OrderService.getByProdId(params);
      if (result.code == 200) {
        if (result.meta && result.meta !== {}) {
          let proName = result.meta.catalogName + result.meta.tempId;
          sessionStorage.setItem("proName", proName);
        }
      }
    }
  }
};
